// 1. 导入
const fs = require('fs')
const path = require('path')
const http = require('http')

// 2. 创建web 服务器实例
const server = http.createServer()

// 3. 启动服务器
server.listen(3000, () => {
    console.log(`server is running .... at 3000`)
})

// 4. 为服务器实例绑定
server.on('request', (req, res) => {
    res.statusCode = 200
    console.log(req.url)
    if (req.url === '/' || req.url === '/index.html') {
        const fullPath = path.join(__dirname, './clock/index.html')
        const resFile = fs.readFileSync(fullPath)
        res.end(resFile)
    } else if (req.url === '/clock.css') {
        const fullPath = path.join(__dirname, './clock/clock.css')
        const resFile = fs.readFileSync(fullPath)
        res.end(resFile)
    } else if (req.url === '/clock.js') {
        const fullPath = path.join(__dirname, './clock/clock.js')
        const resFile = fs.readFileSync(fullPath)
        res.end(resFile)
    }
})